import requests
kb_id = 1178
cate_parent_id = 74953

def post_rich_content_knowledge_detail():
    response = requests.post(
        url='https://kms.datagrand.com/api/v1/knowledge_item/knowledge_details',
        headers={
            'authority': 'kms.datagrand.com',
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9',
            'appauth': 'MTk5ODc1X3dpa2k=',
            'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MzM5MTIwMzAsIm5iZiI6MTczMzkxMjAzMCwianRpIjoiNmY5MzJlNjItMGI0MS00YjhlLWE3ZWYtYjBmZDI0ZjBlYzU1IiwiZXhwIjoxNzM0NTE2ODMwLCJpZGVudGl0eSI6WyJVc2VyXzE3MzE4OTY3OTAiLG51bGxdLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MiLCJ1c2VyX2NsYWltcyI6eyJ1c2VyaWQiOjM3MzMsInVzZXJuYW1lIjoiVXNlcl8xNzMxODk2NzkwIiwibGV2ZWwiOiJcdTY2NmVcdTkwMWFcdTc1MjhcdTYyMzciLCJ1c2VyX25pY2tuYW1lIjoiXHU2NzY4XHU3Mzg5XHU3NDJhIiwidXNlcl9pY29uIjoiLi9hc3NldHMvaW1hZ2VzL2F2YXRhci5zdmciLCJ1c2VyX2NlbnRlcl9pZCI6bnVsbH19.vwqWWRe2aqtBvvtAHK3PjQMfIwfYDTEq3AHEK28nxTM',
            # 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundarySpcRZvkOv3Ba6bPb',
            'cookie':
            'service_type=km; _file_auth_info=eyJBdXRob3JpemF0aW9uIjoiQmVhcmVyIGV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSklVekkxTmlKOS5leUpwWVhRaU9qRTNNek01TVRJd016QXNJbTVpWmlJNk1UY3pNemt4TWpBek1Dd2lhblJwSWpvaU5tWTVNekpsTmpJdE1HSTBNUzAwWWpobExXRTNaV1l0WWpCbVpESTBaakJsWXpVMUlpd2laWGh3SWpveE56TTBOVEUyT0RNd0xDSnBaR1Z1ZEdsMGVTSTZXeUpWYzJWeVh6RTNNekU0T1RZM09UQWlMRzUxYkd4ZExDSm1jbVZ6YUNJNlptRnNjMlVzSW5SNWNHVWlPaUpoWTJObGMzTWlMQ0oxYzJWeVgyTnNZV2x0Y3lJNmV5SjFjMlZ5YVdRaU9qTTNNek1zSW5WelpYSnVZVzFsSWpvaVZYTmxjbDh4TnpNeE9EazJOemt3SWl3aWJHVjJaV3dpT2lKY2RUWTJObVZjZFRrd01XRmNkVGMxTWpoY2RUWXlNemNpTENKMWMyVnlYMjVwWTJ0dVlXMWxJam9pWEhVMk56WTRYSFUzTXpnNVhIVTNOREpoSWl3aWRYTmxjbDlwWTI5dUlqb2lMaTloYzNObGRITXZhVzFoWjJWekwyRjJZWFJoY2k1emRtY2lMQ0oxYzJWeVgyTmxiblJsY2w5cFpDSTZiblZzYkgxOS52d3FXV1JlMmFxdEJ2dnRBSEszUGpRTWZJd2ZZRFRFcTNBSEVLMjhueFRNIiwiQXBwYXV0aCI6Ik1UazVPRGMxWDNkcGEyaz0iLCJYLUFwcC1JZCI6MTk5ODc1LCJYLVNlcnZpY2UtVHlwZSI6ImttIiwiWC1BcHAtTmFtZSI6Indpa2kifQ==; request_session_id_199875_knowledge_base="dgs-hz#1733987199516412#Z2V0X2NhcmRfbWVkaWE=#JiZfc2NvcmUmaW52ZXJ0ZWRfb3JkZXI="#',
            'kms-tag': 'kms',
            # 'origin': 'https://kms.datagrand.com',
            'referer': 'https://kms.datagrand.com/fronted/',
            'sec-ch-ua': '"Not:A-Brand";v="99", "Chromium";v="112"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"macOS"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            # 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 QuarkPC/1.10.5.185',
            'x-app-id': '199875',
            'x-app-name': 'wiki',
            'x-service-type': 'km'
        },
        data={
            'kb_id': str(kb_id),
            'cate_parent_id': str(cate_parent_id),
            'dir_type': '0'
        })
    if response.status_code == 200 or response.status_code == 201:
        response_data = response.json()
        if response_data['status'] == 200:
            return response_data['data']['cate_id'], response_data['data'][
                'knowledge_id']
        else:
            print(f"Error: {response_data}")
            return None, None
    else:
        print(f"HTTP Error: {response.status_code}")
        return None, None


def put_rich_content_knowledge_detail(knowledge_id, name, content,
                                      cate_id):
    data = {
            "knowledge_id": int(knowledge_id),
            "name": name,
            "author": 'admin',
            "content": content,
            "kb_id": int(kb_id),
            "cate_id": int(cate_id),
            "tag_ids": ""
        }
    response = requests.put(
        url='https://kms.datagrand.com/api/v1/knowledge_item/knowledge_details',
        headers={
            'authority': 'kms.datagrand.com',
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9',
            'appauth': 'MTk5ODc1X3dpa2k=',
            'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MzM5MTIwMzAsIm5iZiI6MTczMzkxMjAzMCwianRpIjoiNmY5MzJlNjItMGI0MS00YjhlLWE3ZWYtYjBmZDI0ZjBlYzU1IiwiZXhwIjoxNzM0NTE2ODMwLCJpZGVudGl0eSI6WyJVc2VyXzE3MzE4OTY3OTAiLG51bGxdLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MiLCJ1c2VyX2NsYWltcyI6eyJ1c2VyaWQiOjM3MzMsInVzZXJuYW1lIjoiVXNlcl8xNzMxODk2NzkwIiwibGV2ZWwiOiJcdTY2NmVcdTkwMWFcdTc1MjhcdTYyMzciLCJ1c2VyX25pY2tuYW1lIjoiXHU2NzY4XHU3Mzg5XHU3NDJhIiwidXNlcl9pY29uIjoiLi9hc3NldHMvaW1hZ2VzL2F2YXRhci5zdmciLCJ1c2VyX2NlbnRlcl9pZCI6bnVsbH19.vwqWWRe2aqtBvvtAHK3PjQMfIwfYDTEq3AHEK28nxTM',
            'content-type': 'application/json',
            'cookie': 'service_type=km; _file_auth_info=eyJBdXRob3JpemF0aW9uIjoiQmVhcmVyIGV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSklVekkxTmlKOS5leUpwWVhRaU9qRTNNek01TVRJd016QXNJbTVpWmlJNk1UY3pNemt4TWpBek1Dd2lhblJwSWpvaU5tWTVNekpsTmpJdE1HSTBNUzAwWWpobExXRTNaV1l0WWpCbVpESTBaakJsWXpVMUlpd2laWGh3SWpveE56TTBOVEUyT0RNd0xDSnBaR1Z1ZEdsMGVTSTZXeUpWYzJWeVh6RTNNekU0T1RZM09UQWlMRzUxYkd4ZExDSm1jbVZ6YUNJNlptRnNjMlVzSW5SNWNHVWlPaUpoWTJObGMzTWlMQ0oxYzJWeVgyTnNZV2x0Y3lJNmV5SjFjMlZ5YVdRaU9qTTNNek1zSW5WelpYSnVZVzFsSWpvaVZYTmxjbDh4TnpNeE9EazJOemt3SWl3aWJHVjJaV3dpT2lKY2RUWTJObVZjZFRrd01XRmNkVGMxTWpoY2RUWXlNemNpTENKMWMyVnlYMjVwWTJ0dVlXMWxJam9pWEhVMk56WTRYSFUzTXpnNVhIVTNOREhoSWl3aWRYTmxjbDlwWTI5dUlqb2lMaTloYzNObGRITXZhVzFoWjJWekwyRjJZWFJoY2k1emRtY2lMQ0oxYzJWeVgyTmxiblJsY2w5cFpDSTZiblZzYkgxOS52d3FXV1JlMmFxdEJ2dnRBSEszUGpRTWZJd2ZZRFRFcTNBSEVLMjhueFRNIiwiQXBwYXV0aCI6Ik1UazVPRGMxWDNkcGEyaz0iLCJYLUFwcC1JZCI6MTk5ODc1LCJYLVNlcnZpY2UtVHlwZSI6ImttIiwiWC1BcHAtTmFtZSI6Indpa2kifQ==; request_session_id_199875_knowledge_base="dgs-hz#1733987199516412#Z2V0X2NhcmRfbWVkaWE=#JiZfc2NvcmUmaW52ZXJ0ZWRfb3JkZXI="#',
            'kms-tag': 'kms',
            'origin': 'https://kms.datagrand.com',
            'referer': 'https://kms.datagrand.com/fronted/',
            'sec-ch-ua': '"Not:A-Brand";v="99", "Chromium";v="112"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"macOS"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 QuarkPC/1.10.5.185',
            'x-app-id': '199875',
            'x-app-name': 'wiki',
            'x-service-type': 'km'
        },
        json=data)
    if response.status_code == 200 or response.status_code == 201:
        response_data = response.json()
        if response_data['status'] == 200:
            print(f"Success: {name}")
            return True
        else:
            print(f"Error: {name}")
            print(f"Error: {response_data}")
            return False
    else:
        print(f"HTTP Error: {name}")
        print(f"HTTP Error: {response.status_code}")
        return False
